package com.cn.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.junit.Test;

import com.cn.domain.Users;
import com.cn.service.UserServiceInterface;
import com.cn.utils.AES;
import com.cn.utils.HelperUtil;
import com.opensymphony.xwork2.ActionSupport;
import com.sun.tools.internal.ws.processor.model.Request;
/**
 * 用户进行登录方法
 * @author Hang
 * @date 2016年3月22日上午9:11:56
 * @version
 * 把生活过成段子,把代码写成诗...
 *  Namespace：指定命名空间。
	ParentPackage：指定父包。
	Result：提供了Action结果的映射。（一个结果的映射）
	Results：“Result”注解列表
	ResultPath：指定结果页面的基路径。
	Action：指定Action的访问URL。
	Actions：“Action”注解列表。
	ExceptionMapping：指定异常映射。（映射一个声明异常）
	ExceptionMappings：一级声明异常的数组。
	InterceptorRef：拦截器引用。
	InterceptorRefs：拦截器引用组。
	http://localhost:8080/应用名字/config-browser/actionNames.action
 */
@SuppressWarnings("serial")
@ParentPackage(value = "json-default")  //指定package的名字
@Namespace(value = "/user")
public class LoginAction extends ActionSupport{
	
	private static final Logger LOGGER = LogManager.getLogger(LoginAction.class);
	
	private AES aes = null;
	private UserServiceInterface userService;
	private Users users;
	private HelperUtil helperUtil;
	
	private HttpServletRequest request = ServletActionContext.getRequest();
	
	@Action(value = "userLogin", results = {
			@Result(name = "success", location = "/index.jsp", type="json"),
			@Result(name = "field", location = "/login.jsp", type="json")
	})
	public void UserLogin(){
		String uname = request.getParameter("name");
		String upassword = request.getParameter("password");
		
		LOGGER.info("输入的用户名为:"+uname+"输入的密码为:"+upassword);
		String ip = request.getRemoteAddr();
		//String ip = helperUtil.getIP(request);
		LOGGER.info("IP为:"+ip);
		/*users = userService.getUserByName(uname);
		if(users != null) {
			aes = new AES();
			
		}*/
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public Users getUsers() {
		return users;
	}

	public void setUsers(Users users) {
		this.users = users;
	}
	
	public UserServiceInterface getUserService() {
		return userService;
	}
	@Resource
	public void setUserService(UserServiceInterface userService) {
		this.userService = userService;
	}
	
}
